package com.it.selfAfter.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.selfAfter.entity.PrizeInfo;
import com.it.selfAfter.mapper.PrizeInfoMapper;
import com.it.selfAfter.service.PrizeInfoService;
import com.it.selfAfter.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: Coke
 * @DateTime: 2023/05/20/18:13
 * @注释: TODO
 **/
@Service
@Slf4j
public class PrizeInfoServiceImpl extends ServiceImpl<PrizeInfoMapper, PrizeInfo> implements PrizeInfoService {
    
    @Autowired
    private PrizeInfoMapper prizeInfoMapper;
    @Override
    public PrizeInfo getPrizeInfo (String phone) {
        return prizeInfoMapper.getPrizeInfo(phone);
    }
    
    @Override
    public PrizeInfo updatePrizeInfo (String phone, String count) {
        PrizeInfo prizeInfo = prizeInfoMapper.getPrizeInfo(phone);
        Integer count1 = Integer.valueOf(prizeInfo.getCount());
        if ( "1".equals(count)){
            int i = prizeInfoMapper.updateCount(phone, count1 + 1);
            return  i > 0 ? prizeInfoMapper.getPrizeInfo(phone) : null;
        }else if ("-1".equals(count)){
            int i = prizeInfoMapper.updateCount(phone, count1 - 1);
            return i > 0 ? prizeInfoMapper.getPrizeInfo(phone) : null;
        }
        return null;
    }
}
